const axios = require('axios')
const fs = require('fs')
/**
 * 在这里定义和用户相关的路由处理函数，供 /router/user.js 模块进行调用
 */
 
 // 登录请求的处理函数
//  exports.login = (req, res) => {
//    res.send('login OK')
//  }
exports.login = (req, res) => {
    // const query = req.query
    res.send({
        code: 0,
        data: {value: '干的漂亮'},
        msg: '请求成功'
    })
}

exports.getCard = (req, res) => {
    // const query = req.query
    axios({
        method: 'get',
        url: 'https://ak.hypergryph.com/user/api/inquiry/gacha',
        // url: '/api/user/api/inquiry/gacha',
        params: {
            page: 1,
            token: 'dBVfq7mnagPob2oazcRaf1Bv',
            channelId: 1
        }
    })

    .then(datares => {
        res.send(datares.data)
        console.log(datares.data.data.list)
    })
    .catch(err => {
        res.send(err)
        console.log(err)
        // om.sendSinlgMessage('网络错误，请检查是否先登录官网，保证数据中content字段的有效性。')
    }) 
    
}

exports.index  = (req, res) => {
    fs.readFile("./public/" + req.path.substr(1), (err, data) => {
        // body
        if (err) {
            console.log(err);
            //404：NOT FOUND
            res.writeHead(404, { "Content-Type": "text/html" });
        }
        else {
            //200：OK
            res.writeHead(200, { "Content-Type": "text/html" });
            res.write(data.toString());
        }
        res.end();
    });

}

